package com.lxh.cp.utils;

import com.lxh.cp.config.WxCpConfiguration;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.message.WxCpMessageRouter;

/**
 * created by lanxinghua@2dfire.com on 2020/2/23
 */
public class WxCpUtils {
    public static WxCpService switchover(Integer agentId){
        if (agentId == null){
            throw new IllegalArgumentException("agentId为空");
        }
        WxCpService wxCpService = WxCpConfiguration.getCpService(agentId);
        if (wxCpService == null) {
            throw new IllegalArgumentException(String.format("未找到对应agentId=[%d]的配置，请核实！", agentId));
        }
        return wxCpService;
    }

    public static WxCpMessageRouter getRouter(Integer agentId) {
        if (agentId == null){
            throw new IllegalArgumentException("agentId为空");
        }
        WxCpMessageRouter wxMaMessageRouter = WxCpConfiguration.getRouter(agentId);
        if (wxMaMessageRouter == null) {
            throw new IllegalArgumentException(String.format("未找到对应agentId=[%d]的配置，请核实！", agentId));
        }
        return wxMaMessageRouter;
    }
}
